<?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file license.txt or that can be found at 
 * http://code.google.com/p/billboardce/wiki/License.
 *
 * @package    Sign_IndexController
 * @category   Controller
 * @license    http://code.google.com/p/billboardce/wiki/License New BSD License
 * @version    SVN: $Id: $
 */

/**
 * Main controller for the slide interface to the application
 *
 * @package    Sign_IndexController
 * @category   Controller
 */
class Sign_IndexController extends Zend_Controller_Action 
{   
          
    /**
     * The main sign interface
     *
     */
    public function indexAction()
    {   
        $get = Zend_Registry::get('getFilter');

        if (!isset($get->slideStreamId) || empty($get->slideStreamId)) {
            throw new Ot_Exception_Input('No slidestream ID provided');
        }
        
        $this->view->slideStreamId = $get->slideStreamId;
        $this->_helper->layout()->setLayoutPath(APPLICATION_PATH . '/layouts/');
        $this->_helper->layout()->setLayout('sign');
    }
    
    /**
     * The page to display an image slide
     */
    public function slideAction()
    {
        $this->_helper->layout->disableLayout();
        
        $get = Zend_Registry::get('getFilter');
        
        $slide = new Slide();
        
        $thisSlide = $slide->find($get->slideId);
        
        $this->view->screenHeight = $get->bbceScreenHeight;
        $this->view->screenWidth  = $get->bbceScreenWidth;
        
        if (!is_null($thisSlide)) {
            try {
                $module = Plugin_Slide_Type::factory($thisSlide->slideType);
    
                $this->view->setScriptPath(Plugin_Slide_Type::getPluginPath($thisSlide->slideType));
                $this->_helper->viewRenderer->setViewScriptPathSpec(':action.:suffix');
                
                $module->buildSlide($this->view, $thisSlide->slideId);
            } catch (Exception $e) {
                $this->view->error = $e->getMessage();
            }
        }
    }
    
    
    /**
     * Looks up the data for the given slidestream ID and echoes it as JSON
     * 
     */
    public function getDataAction()
    {
        $get = Zend_Registry::get('getFilter');
        
        if (!isset($get->slideStreamId)) {
            throw new Ot_Exception_Input('No slide stream ID given');
        }
        
        $slideStreamId = $get->slideStreamId;
        
        $slideStreamMap = new Slide_Stream_Map();
        
        $entities = $slideStreamMap->getEntitiesForSlideStream($slideStreamId);
        
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNeverRender();
        
        echo Zend_Json::encode($entities);
    }
}